<?php

class Mstation extends CI_Model {

    private $_table = 'station';
    public function __construct() {
        parent::__construct();
    }
    
    /**
     * Get the list of stations
     */
    public function getStations($params = array()) {
        $this->db->order_by("id", "desc"); 
        if (isset($params['start'])) {
            $this->db->limit(10, $params['start']);
        }
        $query = $this->db->get($this->_table);        
        return $query->result_array();
    }
    
    public function insertStation($data) {
        $this->db->insert($this->_table, $data);
        return $this;
    }
    public function getStation($id) {
        $query = $this->db->get_where($this->_table, array('id' => $id));        
        $result = $query->result_array();
        if (!empty($result)) {
            return $result[0];
        } else {
            return null;
        }
    }
    public function update($station) {        
        $this->db->where('id', $station['id']);
        return $this->db->update($this->_table, $station); 
    }
    
    public function delete($id) {
        return $this->db->delete($this->_table, array('id' => $id)); 
    }
}